package com.budwk.app.sqfwV2.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfw.vo.GenerateExcelUrlVO;
import com.budwk.app.sqfwDoc.dto.CompleteFlowTemplateCodeUpdateDTO;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.DownExcelLedgerReqVo;
import com.budwk.app.sqfwV2.dto.entity.SqfwShopsBaseInfo;
import com.budwk.app.sqfwV2.service.enterpriseWarrantyServe.EnterpriseWarrantyServeService;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.openapi.annotation.ApiResponses;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author zhangp
 * @description TODO
 * @className EnterpriseWarrantyServeController
 * @Date 8:48 2024/4/26
 */
@IocBean
@At("/platform/sqfwV2/enterpriseWarrantyServe")
@ApiDefinition(tag = "世纪城安全巡查表接口管理")
@Slf4j
public class EnterpriseWarrantyServeController {

    @Inject
    private EnterpriseWarrantyServeService enterpriseWarrantyServeService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "保存数据并创建pdf")
    @SLog(tag = "保存数据并创建pdf", value = "${args[0]}")
    public Result<?> submitData(@Param("..") CompleteFlowTemplateCodeUpdateDTO dto) {
        log.info("EnterpriseWarrantyServeController submitData param: {}", JSONObject.toJSONString(dto));
        enterpriseWarrantyServeService.submitData(dto);
        return Result.success();
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "重新生成PDF")
    @SaCheckLogin
    public Result<?> reGeneratePDF(@Param("sqfwFlowId") String sqfwFlowId) {
        log.info("EnterpriseWarrantyServeController reGeneratePDF sqfwFlowId: {}", sqfwFlowId);
        return enterpriseWarrantyServeService.reGeneratePDF(sqfwFlowId);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "下载Excle台账(按照编码下载)（支持批量下载）")
    @ApiResponses(implementation = GenerateExcelUrlVO.class)
    @SaCheckLogin
    public Result<?> downExcelLedger(@Param("..") DownExcelLedgerReqVo reqVo) {
        log.info("EnterpriseWarrantyServeController downExcelLedger reqVo: {}", JSONObject.toJSONString(reqVo));
        reqVo.setAgainGenerate(true);
        return enterpriseWarrantyServeService.downExcelLedger(reqVo);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "下载PDF")
    @ApiResponses(implementation = GenerateExcelUrlVO.class)
    @SaCheckLogin
    public Result<?> downPdfLedger(@Param("..") DownExcelLedgerReqVo reqVo) {
        log.info("EnterpriseWarrantyServeController downPdfLedger reqVo: {}", JSONObject.toJSONString(reqVo));
        reqVo.setAgainGenerate(true);
        return enterpriseWarrantyServeService.downPdfLedger(reqVo);
    }


    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "批量数据检测")
    @ApiResponses(implementation = GenerateExcelUrlVO.class)
    @SaCheckLogin
    public Result<?> isCheckDataBatch(@Param("sqfwIdList") List<String> sqfwIdList) {
        log.info("EnterpriseWarrantyServeController isCheckDataBatch reqVo: {}", JSONObject.toJSONString(sqfwIdList));
        return Result.data(enterpriseWarrantyServeService.isCheckDataBatch(sqfwIdList));
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "模板下载")
    @SaCheckLogin
    public Result<?> downloadTemplate(@Param("index") String index, HttpServletResponse response) {
        log.info("PublicSecurityController downloadTemplate reqVo: {}", index);
        return enterpriseWarrantyServeService.downloadTemplate(index, response);
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "根据输入的查询条件和内容查询商铺名称信息")
    @ApiResponses(implementation = SqfwShopsBaseInfo.class)
    @SaCheckLogin
    public Result<?> getShopInfoListByContent(@Param("content") String content, @Param("pageSize") Integer pageSize, @Param("pageNo") Integer pageNo, @Param("types") List<String> types) {
        log.info("EnterpriseWarrantyServeController getShopInfoListByContent content: {},pageSize{},pageNo{},types{}", content, pageSize, pageNo, types);
        return enterpriseWarrantyServeService.getShopInfoListByContent(content, pageSize, pageNo, types);
    }


    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "根据选择的商铺ID查询最新的记录")
    @ApiResponses(implementation = Sqfw_formSummary_new.class)
    @SaCheckLogin
    public Result<?> getFormSummaryInfoListByShopId(@Param("shopBaseInfoId") String shopBaseInfoId) {
        log.info("EnterpriseWarrantyServeController getFormSummaryInfoListByContent shopBaseInfoId: {}", shopBaseInfoId);
        return enterpriseWarrantyServeService.getFormSummaryInfoListByShopId(shopBaseInfoId);
    }


}
